package com.mrogrape.notepad.ui.library;

import java.awt.Frame;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;

/**
 * 打开资源对话框。
 * 
 * @author Ice Spring
 * @version 1.0
 */
public class OpenResourceDialog extends JDialog {
	
	public OpenResourceDialog(Frame frame) {
		super(frame, true);
		initialize();
	}
	
	private void initialize() {
	
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.TRAILING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
						.addComponent(getResultListView(), Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 398, Short.MAX_VALUE)
						.addComponent(getPanel(), Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 398, Short.MAX_VALUE)
						.addComponent(getTextField(), Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 398, Short.MAX_VALUE)
						.addComponent(getTipsLbl(), Alignment.LEADING)
						.addComponent(getResultLbl(), Alignment.LEADING)
						.addComponent(getDetailTextView(), GroupLayout.DEFAULT_SIZE, 398, Short.MAX_VALUE))
					.addContainerGap())
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addComponent(getTipsLbl())
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(getTextField(), GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(getResultLbl())
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(getResultListView(), GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(getDetailTextView(), GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(getPanel(), GroupLayout.PREFERRED_SIZE, 43, GroupLayout.PREFERRED_SIZE)
					.addContainerGap())
		);
		getContentPane().setLayout(groupLayout);
	}

	
	/** serialVersionUID */
	private static final long serialVersionUID = 1L;
	private JLabel tipsLbl;
	private JTextField textField;
	private JLabel resultLbl;
	private JList resultListView;
	private JPanel panel;
	private JButton closeBtn;
	private JButton openButton;
	private JCheckBox supportedOnlyCheck;
	private JTextField detailTextView;
	private JLabel getTipsLbl() {
		if (this.tipsLbl == null) {
			this.tipsLbl = new JLabel("Select an item to open");
		}
		return this.tipsLbl;
	}
	private JTextField getTextField() {
		if (this.textField == null) {
			this.textField = new JTextField();
			this.textField.setColumns(10);
		}
		return this.textField;
	}
	private JLabel getResultLbl() {
		if (this.resultLbl == null) {
			this.resultLbl = new JLabel("Matching Items:");
		}
		return this.resultLbl;
	}
	private JList getResultListView() {
		if (this.resultListView == null) {
			this.resultListView = new JList();
		}
		return this.resultListView;
	}
	private JPanel getPanel() {
		if (this.panel == null) {
			this.panel = new JPanel();
			GroupLayout gl_panel = new GroupLayout(this.panel);
			gl_panel.setHorizontalGroup(
				gl_panel.createParallelGroup(Alignment.LEADING)
					.addGroup(Alignment.TRAILING, gl_panel.createSequentialGroup()
						.addContainerGap()
						.addComponent(getSupportedOnlyCheck())
						.addPreferredGap(ComponentPlacement.RELATED, 86, Short.MAX_VALUE)
						.addComponent(getOpenButton())
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(getCloseBtn())
						.addContainerGap())
			);
			gl_panel.setVerticalGroup(
				gl_panel.createParallelGroup(Alignment.LEADING)
					.addGroup(Alignment.TRAILING, gl_panel.createSequentialGroup()
						.addContainerGap(12, Short.MAX_VALUE)
						.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
							.addComponent(getCloseBtn())
							.addComponent(getOpenButton())
							.addComponent(getSupportedOnlyCheck()))
						.addContainerGap())
			);
			this.panel.setLayout(gl_panel);
		}
		return this.panel;
	}
	private JButton getCloseBtn() {
		if (this.closeBtn == null) {
			this.closeBtn = new JButton("Close");
		}
		return this.closeBtn;
	}
	private JButton getOpenButton() {
		if (this.openButton == null) {
			this.openButton = new JButton("Open");
		}
		return this.openButton;
	}
	private JCheckBox getSupportedOnlyCheck() {
		if (this.supportedOnlyCheck == null) {
			this.supportedOnlyCheck = new JCheckBox("Show supported only");
		}
		return this.supportedOnlyCheck;
	}
	private JTextField getDetailTextView() {
		if (this.detailTextView == null) {
			this.detailTextView = new JTextField();
			this.detailTextView.setColumns(10);
		}
		return this.detailTextView;
	}
}
